import org.omg.PortableInterceptor.DISCARDING;

import java.util.List;

public class Test {
    //将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。
    public static MySingleList.ListNode mergeTwoLists(MySingleList.ListNode headA, MySingleList.ListNode headB) {
        MySingleList.ListNode newHead = new MySingleList.ListNode(100);
        MySingleList.ListNode tmpHead = newHead;


        while(headA != null && headB !=null){
            if(headA.val > headB.val){
                tmpHead.next = headB;
                headB = headB.next;
            }else {
                tmpHead.next = headA;
                headA = headA.next;
            }
            tmpHead = tmpHead.next;
        }

        if(headA != null){
            tmpHead.next = headA;
        }
        if(headB != null){
            tmpHead.next = headB;
        }
        return newHead.next;
    }

    public static void main(String[] args) {
//        MySingleList mySingleList = new MySingleList();
//        mySingleList.createList();
//        mySingleList.display();
//
//       MySingleList.ListNode slow = mySingleList.countBackwards(2);
//        System.out.println(slow.val);


        MySingleList mySingleList1 = new MySingleList();
        mySingleList1.addLast(12);
        mySingleList1.addLast(23);
        mySingleList1.addLast(34);
        mySingleList1.addLast(45);
        mySingleList1.addLast(56);

        mySingleList1.display();


        MySingleList mySingleList2 = new MySingleList();
        mySingleList2.addLast(8);
        mySingleList2.addLast(15);
        mySingleList2.addLast(30);
        mySingleList2.addLast(40);
        mySingleList2.addLast(78);
        mySingleList2.display();



         mergeTwoLists(mySingleList1.head,mySingleList2.head);


         mySingleList2.display();




    }
}
